﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace Furiant.Figment.Agents
{
    public class StatCollection<T> : 
        IEnumerable<KeyValuePair<StatDefinition, Stat<T>>>
        where T : IComparable
    {
        private readonly Dictionary<StatDefinition, Stat<T>> _collection;

        public StatCollection()
        {
            _collection = new Dictionary<StatDefinition, Stat<T>>();
        }

        public void Add(StatDefinition definition, T value)
        {
            var attr = new Stat<T>(value);
            
            _collection.Add(definition, attr);
        }

        public void Add(StatDefinition definition, Func<IHasStats<T>, IComparable<T>> function)
        {
            var attr = new Stat<T>(function);

            _collection.Add(definition, attr);
        }

        public IEnumerable<StatDefinition> Keys { get { return _collection.Keys; } }

        public IEnumerable<Stat<T>> Values { get { return _collection.Values; } }

        public Stat<T> this[StatDefinition key] { get { return _collection[key]; } }


        public IEnumerator<KeyValuePair<StatDefinition, Stat<T>>> GetEnumerator()
        {
            return _collection.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return _collection.GetEnumerator();
        }
    }
}
